package com.tuozixuan.jmh.demo;

import java.util.concurrent.TimeUnit;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Measurement(iterations = 3, time = 100, timeUnit = TimeUnit.MILLISECONDS)
@Fork(1)
public class JmhDemo_Warmup {

	@Benchmark
	@Warmup(iterations = 3, time = 100, timeUnit = TimeUnit.MILLISECONDS)
	public String concat() {
		String a = "Hello Java";
		String b = "Hello Python";
		
		String c = a + b;
		return c;
	}
	
	@Benchmark
	@Warmup(iterations = 3, time = 100, timeUnit = TimeUnit.MILLISECONDS, batchSize = 100)
	public String concatByBatchWarmup() {
		String a = "Hello Java";
		String b = "Hello Python";
		
		String c = a + b;
		return c;
	}
	
	public static void main(String[] args) throws RunnerException {
		Options opt = new OptionsBuilder().include(JmhDemo_Warmup.class.getSimpleName()).build();
		new Runner(opt).run();
	}
}
